package com.ytjj.qmyx.supplychain.api.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/sentinel")
@RefreshScope
public class SentinelController {
    @Value("${users.name:}")
    private String usersName;
    @Value("${users.age:18}")
    private Integer usersAge;

    /**
     * 限流
     * @return
     */
    @GetMapping("/hello")
    public String hello() {
        return "hello! this is sentinel! name:" + usersName + ", age:" + usersAge;
    }

    /**
     * 限流
     * @return
     */
    @GetMapping("/world")
    public String world() {
        return "world! this is sentinel!";
    }

    /**
     * 降级
     * @return
     */
    @GetMapping("/demote")
    public String demote() {
        try {
            Thread.sleep(new Random().nextInt(2000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "this is sentinel demote!!!";
    }
}
